package cn.krguang.sipphone;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.xuchongyang.easyphone.EasyLinphone;
import com.xuchongyang.easyphone.callback.PhoneCallback;
import com.xuchongyang.easyphone.callback.RegistrationCallback;
import com.xuchongyang.easyphone.service.LinphoneService;

import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCall;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MainActivity extends AppCompatActivity {

    private String TAG = "gggg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (!LinphoneService.isReady()){
            EasyLinphone.startService(this);
            EasyLinphone.addCallback(new RegistrationCallback() {
                @Override
                public void registrationOk() {
                    super.registrationOk();
                    Toast.makeText(MainActivity.this, "登录成功！", Toast.LENGTH_SHORT).show();
                    EasyLinphone.addCallback(null, new PhoneCallback() {
                        @Override
                        public void incomingCall(LinphoneCall linphoneCall) {
                            super.incomingCall(linphoneCall);
                            Log.d(TAG, "incomingCall: 有电话呼入");
                        }

                        @Override
                        public void outgoingInit() {
                            super.outgoingInit();
                        }

                        @Override
                        public void callConnected() {
                            super.callConnected();
                        }

                        @Override
                        public void callEnd() {
                            super.callEnd();
                        }
                    });
                }
                @Override
                public void registrationFailed() {
                    super.registrationFailed();
                    Log.d(TAG, "registrationFailed: 登陆失败");
                }
            },null);
        }

    }

    public void login(View view) {
        EasyLinphone.setAccount("1005","1234","192.168.18.117:5060");
        LinphoneAddress.TransportType transport = LinphoneAddress.TransportType.LinphoneTransportTcp;
        EasyLinphone.login();
    }
}
